package com.hjc.controller;

import com.hjc.entity.CurrentUser;
import com.hjc.entity.OutStore;
import com.hjc.entity.Result;
import com.hjc.entity.Store;
import com.hjc.page.Page;
import com.hjc.service.OutStoreService;
import com.hjc.service.StoreService;
import com.hjc.utils.TokenUtils;
import com.hjc.utils.WarehouseConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/outstore")
public class OutStoreController {
    @Autowired
    private OutStoreService outStoreService;

    @Autowired
    private TokenUtils tokenUtils;

    @Autowired
    private StoreService storeService;

    @RequestMapping("/outstore-add")
    public Result addOutStore(@RequestBody OutStore outStore, @RequestHeader(WarehouseConstants.HEADER_TOKEN_NAME) String token) {
        CurrentUser currentUser = tokenUtils.getCurrentUser(token);
        outStore.setCreateBy(currentUser.getUserId());
        return outStoreService.addOutStore(outStore);
    }

//    http://localhost:3000/api/outstore/store-list?_t=1697640953607
    @RequestMapping("/store-list")
    public Result findAllStore() {
        List<Store> allStore = storeService.findAllStore();
        return Result.ok(allStore);
    }

//    http://localhost:3000/api/outstore/outstore-page-list?
//    storeId=1&productName=&startTime=&endTime=&isOut=&pageSize=5&pageNum=1&totalNum=0
    @RequestMapping("/outstore-page-list")
    public Result findOutStoreByPage(OutStore outStore, Page page) {
        page = outStoreService.findOutStorePage(outStore, page);
        return Result.ok(page);
    }

//    http://localhost:3000/api/outstore/outstore-confirm
    @RequestMapping("/outstore-confirm")
    public Result confirmOutStore(@RequestBody OutStore outStore) {
        return outStoreService.confirmOutStore(outStore);
    }


}
